Exchange API icon

Exchange API

(0 reviews)

Share Assets

Assets can be shared to other users between the same organization.

The share model contemplates being able to add certain permissions to users to be able to view or edit the asset. These permissions are:
viewer: allows you to see the asset but not do any type of editing on it
contributor: allows editing of the asset's metadata and portal and creating new versions of it
admin: allows other types of operations such as sharing with other users or deprecating and deleting versions

To do that, there are some examples of how to share an asset to other users.

Before executing the examples, read the Anypoint Platform Token section to know how to obtain the token to be used in the examples. This should be replaced for the value ANYPOINT_TOKEN in each curl example.

The examples have been made by cURL, but optionally, instead of sending HTTP commands with cURL, you can use Postman or another application.

Note: Sharing and asset to internal and external organizations will be eventually available in the Exchange API v2

How to share an asset to another user

Before executing the example, these URL parameters should be replaced
:groupId: Group ID of the asset to be shared
:assetId: Asset ID of the asset to be shared

The body of the request is an array of user assignments (it could be found after the -d flag). Each assignment has these properties:
userId: The ID of the user to be shared the asset
role: The role to be assigned to the user against the asset. It could have any of these values: "viewer", "contributor" or "admin".

An IMPORTANT observation is that the user role assignments will override all the current assignments of the asset. That means, if a new user assignment wants to be added to an asset, then all the current assignments must be added with the new user assignment to be added.

An example about to override the user assignments of the asset:

curl --location --request PUT 'https://anypoint.mulesoft.com/exchange/api/v1/assets/:groupId/:assetId/users' \
--header 'Authorization: ANYPOINT_TOKEN' \
--header 'Content-Type: application/json' \
-d '[{
    "userId": "99685226-c802-4fc6-8c7d-d159737784bb",
    "role": "viewer"
}]'

An example of getting the current users that have permissions over the asset:

curl --location --request GET 'https://anypoint.mulesoft.com/exchange/api/v1/assets/:groupId/:assetId/users' \
--header 'Authorization: Bearer ANYPOINT_TOKEN' \
--header 'Content-Type: application/json'

A response like this will be retrieved. Where each user with the assigned role can be seen.

[
    {
        "identityType": "user",
        "username": "john-smith",
        "firstName": "John",
        "lastName": "Smith",
        "email": "john.smith@gmail.com",
        "id": "99685226-c802-4fc6-8c7d-d159737784bb",
        "role": "contributor",
        "roleId": "56aeef8b-ca02-4b7f-8382-daee929c7139",
        "createdAt": "2020-09-21T19:36:59.198626",
        "organization": {
            "id": "5a673b98-92f4-459d-b950-daeed7a8165d",
            "name": "Mythical Ventures",
            "isMulesoftOrganization": false
        }
    }
]

Reviews